<template>
  <div class="updata">
    <form action="JavaScript:;">
      <input type="text" placeholder="请输入用户名" v-model="updataInfo.username" maxlength="18">
      <input type="password" placeholder="请输入密码" v-model="updataInfo.password" maxlength="18">
      <input type="password" placeholder="请输入新密码" v-model="updataInfo.newPassword" maxlength="18">
      <button class="btn" @click="updata">修改</button>
    </form>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
  name: 'Updata',

  data() {
    return {
      updataInfo:{ // 修改密码信息
        username: '', // 用户名
        password: '', // 密码
        newPassword: '' // 新密码
      }
    };
  },

  methods: {
    // 修改密码
    updata(){
      let {username,password,newPassword} = this.updataInfo
      if(username.trim() && password.trim() && newPassword.trim()){
        this.$api.updataPassword(this.updataInfo).then(res => {
          if(res == 1){
            this.showHint({title:'修改成功!',isFlag:true})
            this.$parent.isPage = 0
          }else{
            this.showHint({title:res,isFlag:false})
          }
        })
      }else{
        this.showHint({title:'用户名和密码不能为空!',isFlag:false})
      }
    },
    ...mapActions(['showHint'])
  },
};
</script>

<style scoped>

</style>